<include file="Public:header" />
<link rel="stylesheet" href="__PUBLIC__/Home/css/duobao.css" id="theme" />
<link rel="stylesheet" href="__PUBLIC__/Home/css/pagination.css">
<link rel="stylesheet" href="__PUBLIC__/Home/css/pagination-common.css">
<script src="http://static.runoob.com/assets/jquery-validation-1.14.0/dist/jquery.validate.min.js"></script>
<div class='sep'></div>
<div class="autobox " style='margin-top:20px;'>
    <div class="left w215 ">
        <div class="user-panel">
            <div class="user-info">
                <dl>
                    <dt class='user-logo'>
                    <img src="https://www.a5.net/uc_server/images/noavatar_small.gif" onerror="this.onerror=null;this.src='https://www.a5.net/uc_server/images/noavatar_small.gif'"> <i></i>
                </dt>
                    <dd class='username'>
                        <a href="#">{$Think.session.user.username}</a>
                    </dd>
                    <!-- ￥ -->
                    <dd class="total"><i class='fa fa-rmb'></i> 交易额：</dd>
                    <dd class='total-money'>{$total1}元
                    </dd>
                </dl>
                <div class="dashedline"></div>
            </div>
            <ul class="deal-info">
                <li>
                    <a href="plugin.php?id=guarantee:guarantee&amp;item=status_4">
                        <div>交易中</div>
                        <div class='jiaoyi-count'>{$total2}</div>
                    </a>
                </li>
                <li style="border:none;">
                    <a href="plugin.php?id=guarantee:guarantee&amp;item=status_6">
                        <div>已结束</div>
                        <div class='jiaoyi-count'>{$total3}</div>
                    </a>
                </li>
            </ul>


            <div class="post-deal">
                <a class="btn" href="{:U('duobao/add')}" target="_blank">
                    <i class=' fa fa-plus-square-o'></i> 发起交易
                </a>
            </div>
            <div class="tips">
                <i class='fa fa-check-circle-o'></i> 安全 便捷 高效
            </div>
        </div>
        <div class="flow">
            <section class="con-side">
                <header>
                    <h2 class="f5">
                        <i class='fa fa-list-ol'></i> 担保交易流程
                    </h2>
                </header>
                <article class="flow-content">

                    <dl>
                        <dt>
                        <i class='step1' ></i>
                        </dt>
                        <dd>
                            <strong>发起交易</strong>
                            <span>只需一方发起即可</span>
                        </dd>
                    </dl>
                    <dl>
                        <dt>
                        <i class='step2'></i>
                        </dt>
                        <dd>
                            <strong>对方接受</strong>
                            <span>点击按钮 接受交易</span>
                        </dd>
                    </dl>
                    <dl>
                        <dt>
                        <i class='step3'></i>
                        </dt>
                        <dd>
                            <strong>买家付款</strong>
                            <span> 双方开始交易</span>
                        </dd>
                    </dl>
                    <dl class="p0">
                        <dt>
                        <i class='step4'></i>
                        </dt>
                        <dd>
                            <strong>交易结束</strong>
                            <span>每天10点和17点统一支付</span>
                        </dd>
                    </dl>
                </article>
            </section>
        </div>
    </div>
    <div class="left right-content">
        <div class="con-right-post" style='padding-left:0px;padding-right:0px;'>
            <div class="hd" style='margin-left:5px;margin-right:5px;'>
                <h2 class="left">
                    <i class='fa fa-list fa-fw'></i> 我的交易信息列表
                </h2>
            </div>

            <div class="bd">
                <ul class='deal-tab'>
                    <li <eq name="status" value="0">
                        class='active'
                        </eq>
                        data-id='0'>所有交易</li>
                    <li <eq name="status" value="1">
                        class='active'
                        </eq> data-id='1' >交易中</li>
                    <li <eq name="status" value="2">
                        class='active'
                        </eq> data-id='2'>已成功</li>
                    <li <eq name="status" value="3">
                        class='active'
                        </eq> data-id='3'>已失败</li>
                </ul>
                <ul class='deal-list'>
                    <li class='deal-item'>
                        <div>日期</div>
                        <div>交易编号</div>
                        <div>交易内容</div>
                        <div>交易状态</div>
                        <div>交易操作</div>
                    </li>
                </ul>
                <ul class='deal-list' id='data-panel'>

                </ul>
                <div class=" m-style M-box "></div>
            </div>
        </div>
    </div>
</div>
<script src="__PUBLIC__/Home/js/jquery.pagination.js "></script>
<script>
    var status = "{$status} ";
    var userId = "{:userid()}";
    var data = {
        page: 1,
        status: status
    };
    $.getJSON('{:U("transactionList")}', data, function(json) {
        handleData(json);
    });
    $('.M-box').pagination({
        pageCount: 10,
        totalData: "{$count} ",
        showData: 5,
        jump: true,
        coping: true,
        homePage: '首页',
        endPage: '末页',
        prevContent: '上页',
        nextContent: '下页',
        callback: function(api) {
            $('.now').text(api.getCurrent());
            var data = {
                page: api.getCurrent(),
                status: status
            };
            $.getJSON('{:U("transactionList ")}', data, function(json) {
                handleData(json);
            });
        }
    }, function(api) {
        $('.now').text(api.getCurrent());
    });

    function handleData(json) {
        if (json == undefined || json == null || $.trim(json) == '') {
            return;
        }

        $('#data-panel').empty();
        $.each(json, function(index, ele) {
            var content = " ";
            if (userId == ele.user_id) {
                if (ele.role == 1) {

                    content = "<span style='color:#f66'>¥" + ele.coin_total + "元</span>&nbsp;&nbsp;<span>卖方:" + ele.other_side_username + "</span>";
                } else {
                    content = "<span style='color:#f66'>¥" + ele.other_coin_total + "元</span>&nbsp;&nbsp;<span>买方:" + ele.phone + "</span>";
                }
            } else {
                if (ele.role == 1) {

                    content = "<span style='color:#f66'>¥" + ele.other_coin_total + "元</span>&nbsp;&nbsp;<span>买方:" + ele.phone + "</span>";
                } else {
                    content = "<span style='color:#f66'>¥" + ele.coin_total + "元</span>&nbsp;&nbsp;<span>卖方:" + ele.other_side_username + "</span>";
                }
            }
            var itemHtml = "<li class = 'deal-item' > \n " +
                " <div> " + ele.create_time +
                " </div> \n " +
                " <div> " + ele.business_no + "</div> \n " +
                " <div> " + content + " </div>\n" +
                " <div> " + (ele.status == 1 ? "已发起 " : (ele.status == 2 ? "对方接受 " : "对方拒绝 ")) + " </div> \n " +
                " <div><a style = 'color:#f80;' href = 'detail?id=" + ele.id + "' > 查看详细 </a> </div> \n " +
                " </li>";
            $('#data-panel').append(itemHtml);
        });
    }
</script>
<script>
    $(function() {

        $(".deal-tab").on('click', 'li', function() {
            if (!$(this).hasClass('active')) {

                $(this).siblings().removeClass('active');
                $(this).addClass('active');
            }

            window.location.href = 'index?status=' + $(this).attr('data-id');

        })
    });
</script>
<include file="Public:footer" />